package com.sdk.springbootsdkuser.controller;


import com.sdk.cachesdk.service.CacheService;
import com.sdk.springbootsdk.common.FluxRuntimeException;
import com.sdk.springbootsdk.config.TrackPlateModelProp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class SdkController {

    @Autowired
    private TrackPlateModelProp trackPlateModelProp;
    @Resource
    private CacheService localCache;
    @Resource
    private CacheService distributedCache;

    @GetMapping("plate-models")
    public Object getPlateModels() {
        return trackPlateModelProp.getPlateModels();
    }

    @GetMapping("cache")
    public Object getCache() {
        localCache.set("time", System.currentTimeMillis());
        System.out.println("localcache = " + localCache.get("time", Long.class));
        distributedCache.set("time1", System.currentTimeMillis());
        System.out.println("distributedCache = " + distributedCache.get("time1", Long.class));
        return 0;
    }

    @GetMapping("exception")
    public Object exception() {
        throw new FluxRuntimeException("exception");
    }
}
